package com.hzzy.controller;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hzzy.entity.MenuEntity;
import com.hzzy.service.HzMenuService;
import com.hzzy.service.HzPermissionTypeService;

/**
 * 配置权限
 * @author hjb
 * 2016年5月24日
 */
@Controller
@RequestMapping("/configuration")
public class CompetenceController {
	
	@Resource
	private HzPermissionTypeService hzPermissionTypeService;

	@Resource
	private HzMenuService hzMenuService;
	/**
	 * 查询需要配置权限的职位信息
	 * @param model
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/queryCompetence")
	public String queryCompetence(Model model, HttpServletRequest request) {
		
		model.addAttribute("permissionTypeList", hzPermissionTypeService.getAllData());
		
		return "rightContent.competenceList";
	}
	
	@ResponseBody
	@RequestMapping(value="/editCompetence")
	public List<MenuEntity> editCompetence(Model model, HttpServletRequest request) {
		String typeId = request.getParameter("positionId");
		List<MenuEntity> menuEntityList = null;
		if (StringUtils.isNotEmpty(typeId)) {
			menuEntityList = hzMenuService.getMenuEntityList(Integer.parseInt(typeId));
		} else {
			menuEntityList = new ArrayList<MenuEntity>();
			menuEntityList.add(new MenuEntity("异常错误，请刷新！"));
		}
		return menuEntityList;
	}
	
}
